<template>
	<view class="main tn-flex" @click="gouser(topicItem.id)">
		<view class="left">
			<image :src="topicItem.userAvatar" mode=""></image>
		</view>
		<view class="right">
			<view class="lv-name tn-flex tn-flex-col-center">
				<view class="name">{{topicItem.userName}}</view>
				<!-- <view class="lv" v-if="topicItem.vip == 1">
					<text>{{topicItem.vip_lv}}</text> -->
					<!-- <image v-if="topicItem.lv == 1" src="/static/my/v1.png" mode="" class="v-icon"></image>
					<image v-if="topicItem.lv == 2" src="/static/my/v2.png" mode="" class="v-icon"></image>
					<image v-if="topicItem.lv == 3" src="/static/my/v3.png" mode="" class="v-icon"></image>
					<image v-if="topicItem.lv == 4" src="/static/my/v4.png" mode="" class="v-icon"></image> -->
				<!-- </view> -->
				
				<!-- 置顶标识 -->
				<!-- <view v-if="topicItem.is_ding == 1" class="my-tding" >
					<image src="/static/index/tding.png" mode=""></image>
				</view> -->
				
			</view>
			<view class="time">{{topicItem.date}}
				<template v-if="!isAuditVersion">
					发布于{{topicItem.city}}
				</template>
			</view>
			<!-- 删除帖子 -->
			<view class="del" v-if="type == 1" @click.stop="del(topicItem.id)">删除帖子</view>
			<!-- 内容主体部分 图文-->
			<view class="content" v-if="topicItem.price_is<=0">
				<view class="details">{{topicItem.content}}</view>
				<view class="imgList" v-if="topicItem.mainImage.length > 0">
					<block v-for="(item_img,index) in topicItem.mainImage" :key="index">
						<view class="image" @click.stop="previewImage(index)">
							<w-image :src="item_img" width="188rpx" height="188rpx" radius="10rpx"></w-image>
						</view>
					</block>
				</view>
			</view>
			<!-- 付费帖子 -->
			<view class="content" v-if="topicItem.price_is>0">
				<view class="pay tn-flex tn-flex-col-center">
					<text class="pay-tag">#付费贴</text>
					<view class="details">
						付费帖子，您需要支付<text class="price">{{topicItem.price_is}}</text>海豚币
					</view>
				</view>
			</view>
			<!-- 视频 v-if="topicItem.price_is<=0"-->
			<view class="content" v-if="topicItem.vod && topicItem.price_is<=0">
				<!-- <view class="details">有问有答</view> -->
				<view class="video-kuai">
					<image :src="topicItem.vod_img" class="fenmian" mode=""></image>
					<image src="https://peiwanblogs.huolieniaowangluo.com/wx-image/wfw/bofang.png" class="bofang-icon"
						mode=""></image>
				</view>
			</view>
			<!-- 语音 -->
			<view class="content" v-if="topicItem.voc && topicItem.price_is<=0">
				<!-- <view class="details">斤斤计较</view> -->
				<view class="voice tn-flex tn-flex-col-center" @click.stop="play">
					<!-- 未播放 -->
					<image src="/static/my/play.png" v-if="!isPlay" class="play" mode=""></image>
					<!-- 播放中 -->
					<image src="https://web.lanmei.co/image/pause.png" v-else class="play" mode=""></image>
					<!-- op-animation -->
					<image src="/static/my/playIcon.png" class="playIcon" :class="{'op-animation':isPlay}" mode="">
					</image>
					<text class="s">{{topicItem.vocscend}}s</text>
					<!-- <text class="s">{{item.isplay}}s</text> -->

				</view>
			</view>
			<!-- 话题 -->

			<view class="topic-list tn-flex tn-flex-wrap" v-if="topicItem.label.length>0">
				<block v-for="(item_label,index) in topicItem.label" :key="index">
					<view class="topic-list-item" @click.stop="goTagsList(item_label.id)">
						<text class="t1">#</text>
						<text class="t2">{{item_label.title}}</text>
					</view>
				</block>
			</view>
			<!-- 脚步 -->
			<view class="foot tn-flex tn-flex-row-between">
				<view class="foot-left tn-flex tn-flex-col-center" v-if="topicItem.viewUser.viewUserCount > 0">
					<tn-avatar-group size="sm" :lists="topicItem.viewUser.latestUserAvatar"></tn-avatar-group>
					<text class="num">{{topicItem.viewUser.viewUserCount}}人</text>
				</view>
				<view class="" v-else></view>
				<view class="foot-right tn-flex tn-flex-col-center">
					<view class="foot-right-item" @click.stop="upvote(topicItem.id)">
						<image src="/static/index/dianzhan.png" mode="" v-if="!topicItem.is_like" class="img1"></image>
						<image src="/static/index/dianzhan1.png" v-if="topicItem.is_like" class="img1" :class="{'zoom':Ascale}" mode="">
						</image>
						<image src="/static/index/dianzhan1.png" v-if="topicItem.is_like && Ascale"
							class="piaofu" mode="">
						</image>
						<text class="num">{{topicItem.likeCount}}</text>
					</view>
					<view class="foot-right-item">
						<image src="/static/index/pinglun.png" mode="" class="img2"></image>
						<text class="num">{{topicItem.commentCount}}</text>
					</view>
					<view class="foot-right-item" @click.stop="clickTerad(topicItem.id)">
						<image src="/static/index/tread.png" mode="" v-if="topicItem.is_tread == 0" class="img3">
						</image>
						<image src="/static/index/tread1.png" mode="" v-else class="img3" :class="{'fangda':trample}">
						</image>
						<text class="num">{{topicItem.tread_num}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// const audioContext = uni.createInnerAudioContext()
	export default {
		props: {
			item: {
				type: Object
			},
			type: {
				type: Number
			},
			isIndex: {
				type: Number
			},
			isPlay: {
				type: Boolean
			}
		},
		data() {
			return {
				groupList: [{
						src: 'https://demo.com/avatar/xiaomai1.jpg'
					},
					{
						src: 'https://demo.com/avatar/xiaomai1.jpg'
					}
				],
				videoUrl: 'https://img.cdn.aliyun.dcloud.net.cn/guide/uniapp/%E7%AC%AC1%E8%AE%B2%EF%BC%88uni-app%E4%BA%A7%E5%93%81%E4%BB%8B%E7%BB%8D%EF%BC%89-%20DCloud%E5%AE%98%E6%96%B9%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B@20200317.mp4',
				zan: 0,
				tread: 0,
				topicItem: '',
				Ascale: false,
				trample: false,
				isAuditVersion: getApp().globalData.isAuditVersion
			}
		},
		watch: {
			item: {
				handler(n, o) {
					this.topicItem = n
				},
				deep: true,
				immediate: true
			}
		},
		// mounted() {
		// 	if(this.topicItem.voc){
		// 		audioContext.onEnded(res => {
		// 			console.log('结束了')
		// 			this.topicItem.isplay = false
		// 		})

		// 	}

		// },

		methods: {
			async upvote(id) {
				let result = await this.$request({
					loading: 0,
					method: 'GET',
					url: '/api/user/likeGoods',
					data: {
						id,
					}
				})
				this.topicItem.is_like = !this.topicItem.is_like
				if (this.topicItem.is_like) {
					this.Ascale = true
					setTimeout(() => {
						this.Ascale = false
					}, 1500)
					this.topicItem.likeCount += 1
				} else {
					this.topicItem.likeCount -= 1
				}
			},

			async clickTerad(id) {
				try {
					let result = await this.$request({
						loading: 0,
						method: 'post',
						url: '/api/user/treadGoods',
						data: {
							id,
						}
					})
					this.topicItem.is_tread = this.topicItem.is_tread == 0 ? 1 : 0
					if (this.topicItem.is_tread == 0) {
						this.topicItem.tread_num--
					} else {
						this.trample = true
						setTimeout(() => {
							this.trample = false
						}, 1500)
						this.topicItem.tread_num++
					}
				} catch (e) {
					console.log(e)
					this.msg(e.data.msg)
				}
			},
			// 图片预览
			previewImage(current) {
				uni.previewImage({
					urls: this.topicItem.mainImage,
					current,
					loop: true,
					longPressActions: {
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data
								.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},

			gouser(id) {
				uni.navigateTo({
					url: "/circlePages/details?id=" + id
				})
			},
			goTagsList(id) {
				uni.navigateTo({
					url: "/circlePages/tags_list?id=" + id
				})
			},
			// 播放语音
			play() {
				// uni.$emit('audioPlay',{index:this.isIndex})
				this.$emit('audioPlay', this.isIndex)
				// !this.topicItem.isplay ? audioContext.src = this.topicItem.voc : ''
				// this.topicItem.isplay = !this.topicItem.isplay
				// this.topicItem.isplay ? audioContext.play() : audioContext.pause()
			},
			// 删除帖子
			del(id) {
				this.$emit('del', id)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		//border-bottom: 1px solid #1E1F2E;

		margin-bottom: 32rpx;
		background: #ffffff;
		padding: 15px;
		border-radius: 8px;

		.left {
			image {
				width: 72rpx;
				height: 72rpx;
				border-radius: 50%;
			}
		}

		.right {
			padding-left: 20rpx;
			flex: 1;
			position: relative;

			.del {
				position: absolute;
				right: 0;
				top: 10rpx;
				font-size: 26rpx;
				font-weight: 400;
				color: #f95b52;
			}

			.lv-name {
				.name {
					font-size: 26rpx;
					font-weight: bold;
					color: #333333;
				}

				.lv {
					margin-left: 10rpx;
					width: 134rpx;
					height: 32rpx;
					background: url('https://peiwanblogs.huolieniaowangluo.com/wx-image/wfw/vipbg1.png') no-repeat;
					background-size: 100%;
					display: flex;
					align-items: center;

					text {
						font-size: 22rpx;
						font-weight: bold;
						color: #FFFFFF;
						margin-left: 85rpx;
					}




				}
			}

			.time {
				font-size: 22rpx;
				font-weight: 400;
				color: #999999;
				margin-top: 4rpx;
				// margin-bottom: 20rpx;
			}

			// 图文
			.content {
				padding-top: 20rpx;

				.details {
					// margin-top: 20rpx;
					margin-bottom: 24rpx;
					font-size: 28rpx;
					font-weight: 400;
					color: #333333;

					.price {
						color: #FF2626;
					}
				}

				.imgList {
					display: flex;
					flex-wrap: wrap;

					.image {
						margin: 0 17rpx 17rpx 0;
					}
				}

				.imgList .image:nth-child(3n) {
					margin-right: 0;
				}

				.pay {
					margin-bottom: 16rpx;

					.details {
						margin-bottom: 0;
					}
				}

				.pay-tag {
					font-size: 28rpx;
					font-weight: 400;
					color: #CFACFF;
					margin-right: 24rpx;
				}

				.video-kuai {
					margin-bottom: 16rpx;
					position: relative;

					.fenmian {
						width: 100%;
						height: 400rpx;
					}

					.bofang-icon {
						width: 60rpx;
						height: 60rpx;
						position: absolute;
						top: 50%;
						left: 50%;
						transform: translate(-50%, -50%);
					}

				}

				.voice {
					width: fit-content;
					height: 72rpx;
					background: linear-gradient(180deg, #DB89F5 0%, #834BF4 100%);
					border-radius: 45rpx;
					padding: 0 16rpx;
					margin-bottom: 16rpx;

					.play {
						width: 48rpx;
						height: 48rpx;
					}

					.playIcon {
						width: 133rpx;
						height: 44rpx;
						margin: 0 16rpx;
					}

					.op-animation {
						animation: identifier 0.5s infinite;
					}

					.s {
						font-size: 28rpx;
						font-weight: 400;
						color: #FFFFFF;
					}
				}

			}

			@keyframes identifier {
				0% {
					opacity: 0.8;
				}

				50% {
					opacity: 0.5;
				}

				100% {
					opacity: 0.3;
				}
			}

			.topic-list {
				margin-top: 8rpx;

				.topic-list-item {
					font-size: 24rpx;
					font-weight: 400;
					background-color: rgba(153, 153, 153, 0.28);
					padding: 6rpx 16rpx;
					border-radius: 24rpx;
					margin: 0 10rpx 10rpx 0;

					.t1 {
						color: #FFB2F9;
					}

					.t2 {
						color: #333333ad;
					}
				}
			}

			.foot {
				margin-top: 14rpx;

				.foot-left {
					.num {
						font-size: 24rpx;
						font-weight: 400;
						color: #FFFFFF;
						margin-left: 6rpx;
					}
				}

				.foot-right {
					position: relative;

					&-item {
						display: flex;
						align-items: center;
						margin-left: 24rpx;

					}

					.num {
						font-size: 24rpx;
						font-weight: 400;
						color: #999999;
						margin-left: 10rpx;
					}

					.img1 {
						width: 32rpx;
						height: 33rpx;
						z-index: 1;
					}

					.zoom {
						animation: scaleAnimation .5s;
					}

					@keyframes scaleAnimation {
						0% {
							transform: scale(0.4);
						}

						50% {
							transform: scale(1.2);
						}

						100% {
							transform: scale(1);
						}
					}

					.piaofu {
						width: 32rpx;
						height: 33rpx;
						position: absolute;
						top: 0;
						animation: f 1.5s ease-in-out;
					}

					@keyframes f {
						0% {
							top: 0;
							opacity: 1;
						}

						100% {
							top: -100rpx;
							opacity: 0;
						}
					}

					.img2 {
						width: 34rpx;
						height: 31rpx;
					}

					.img3 {
						width: 32rpx;
						height: 34rpx;
					}

					.fangda {
						animation: fangda 0.5s linear;
					}

					@keyframes fangda {
						0% {
							transform: scale(1, 1);
						}

						25% {
							transform: scale(0.4, 0.4);

						}

						70% {
							transform: scale(1.2, 1.2);
						}

						100% {
							transform: scale(1, 1);
						}
					}
				}
			}
		}
	}
	.my-tding{
		width: 30rpx;
		height: 30rpx;
		margin-left: 16rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
</style>
